package com.esri.android.map;

import android.util.Log;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.core.analysis.Viewshed;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.map.AnalysisLayerInternal;
import com.esri.core.internal.map.RasterLayerInternal;
import com.esri.core.io.UserCredentials;
import com.esri.core.raster.FileRasterSource;
import com.esri.core.raster.FunctionRasterSource;
import com.esri.core.raster.RasterSource;
import com.esri.core.renderer.ColormapRenderer;
import com.esri.core.renderer.RasterRenderer;

/* loaded from: classes.dex */
public class RasterLayer extends Layer {
    private RasterRenderer a;
    private RasterSource b;
    private boolean c;

    public RasterLayer(RasterSource rasterSource) {
        super(false);
        this.c = false;
        this.b = rasterSource;
        initLayer();
    }

    @Override // com.esri.android.map.Layer
    protected long create() {
        return RasterLayerInternal.a(this);
    }

    @Override // com.esri.android.map.Layer
    protected void initLayer() {
        try {
            RasterSource rasterSource = this.b;
            if (rasterSource instanceof FileRasterSource) {
                if (this.nativeHandle == 0) {
                    this.nativeHandle = create();
                }
                RasterLayerInternal.a(this.nativeHandle, ((FileRasterSource) this.b).getId());
            } else if (rasterSource instanceof FunctionRasterSource) {
                this.c = true;
                if (this.nativeHandle == 0) {
                    this.nativeHandle = AnalysisLayerInternal.a();
                }
                AnalysisLayerInternal.a(this.nativeHandle, ((FunctionRasterSource) this.b).getId());
            }
            if (this.nativeHandle != 0) {
                SpatialReference spatialReference = null;
                if (!this.c) {
                    spatialReference = SpatialReference.create(RasterLayerInternal.d(this.nativeHandle));
                } else if (AnalysisLayerInternal.a(this.nativeHandle, SpatialReference.WKID_WGS84)) {
                    spatialReference = SpatialReference.create(SpatialReference.WKID_WGS84);
                }
                setDefaultSpatialReference(spatialReference);
                setFullExtent(getFullExtent());
                changeStatus(OnStatusChangedListener.STATUS.INITIALIZED);
                return;
            }
            Log.e(com.esri.core.internal.a.a, "Could not access the raster source.");
            changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_RASTER_LAYER));
        } catch (Exception e) {
            Log.e(com.esri.core.internal.a.a, "Could not access the raster source.", e);
            changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_RASTER_LAYER));
        }
    }

    @Override // com.esri.android.map.Layer
    public void reinitializeLayer(UserCredentials userCredentials) {
        super.reinitializeLayer(userCredentials);
    }

    public float getBrightness() {
        if (this.c) {
            Log.w(com.esri.core.internal.a.a, "Method getBrightness() is not yet supported for FunctionRasterSource.");
            return Float.NaN;
        }
        return RasterLayerInternal.a(this.nativeHandle);
    }

    public void setBrightness(float f) {
        if (this.c) {
            Log.w(com.esri.core.internal.a.a, "Method setBrightness(float) is not yet supported for FunctionRasterSource.");
        } else {
            RasterLayerInternal.a(this.nativeHandle, f);
        }
    }

    public float getContrast() {
        if (this.c) {
            Log.w(com.esri.core.internal.a.a, "Method getContrast() is not yet supported for FunctionRasterSource.");
            return Float.NaN;
        }
        return RasterLayerInternal.b(this.nativeHandle);
    }

    public void setContrast(float f) {
        if (this.c) {
            Log.w(com.esri.core.internal.a.a, "Method setContrast(float) is not yet supported for FunctionRasterSource.");
        } else {
            RasterLayerInternal.b(this.nativeHandle, f);
        }
    }

    public float getGamma() {
        if (this.c) {
            Log.w(com.esri.core.internal.a.a, "Method getGamma() is not yet supported for FunctionRasterSource.");
            return Float.NaN;
        }
        return RasterLayerInternal.c(this.nativeHandle);
    }

    public void setGamma(float f) {
        if (this.c) {
            Log.w(com.esri.core.internal.a.a, "Method setGamma(float) is not yet supported for FunctionRasterSource.");
        } else {
            RasterLayerInternal.c(this.nativeHandle, f);
        }
    }

    public void setRenderer(RasterRenderer rasterRenderer) {
        if (this.c) {
            if (rasterRenderer instanceof ColormapRenderer) {
                com.esri.core.analysis.b.a((Viewshed) ((FunctionRasterSource) this.b).getFunctions().getLast(), (ColormapRenderer) rasterRenderer);
                this.a = rasterRenderer;
                return;
            }
            Log.w(com.esri.core.internal.a.a, "Method setRenderer(RasterRenderer) is not yet supported for FunctionRasterSource.");
            return;
        }
        RasterLayerInternal.a(this.nativeHandle, rasterRenderer);
        this.a = rasterRenderer;
    }

    public RasterRenderer getRenderer() {
        return this.a;
    }

    @Override // com.esri.android.map.Layer
    public Envelope getFullExtent() {
        return super.getFullExtent();
    }

    public RasterSource getRasterSource() {
        return this.b;
    }
}
